<?php


namespace app\cms\home\api\merchant;


use app\cms\authCallBack\merchant;
use app\cms\dto\merchant\merchantInfo;
use app\cms\model\merchant\merchantModel;
use iflow\auth\lib\authAnnotation;
use iflow\Response;
use iflow\Router\Controller;
use iflow\Router\implement\Request\{ GetMapping, PostMapping };

#[Controller('%cmsHome%/merchant_management')]
class merchantManagement
{

    /**
     * 前端商户管理后台 入口
     * @return Response
     */
    #[GetMapping]
    #[authAnnotation('merchant_management', '*')]
    public function getMerchant(): Response
    {
        return (new merchantModel()) -> getMerchant(session('userInfo')['uid'], true);
    }

    /**
     * 创建商户
     * @param merchantInfo $merchantInfo
     * @return Response
     */
    #[PostMapping]
    #[authAnnotation('merchant_management', '*', merchant::class . "@userMerchantNotExists")]
    public function createMerchant(merchantInfo $merchantInfo): Response
    {
        return (new merchantModel()) -> createMerchant($merchantInfo);
    }

    /**
     * 更新商户信息
     * @param merchantInfo $merchantInfo
     * @return Response
     */
    #[PostMapping]
    #[authAnnotation('merchant_management', '*', merchant::class . "@userMerchantExists")]
    public function updateMerchant(merchantInfo $merchantInfo): Response
    {
        return (new merchantModel()) -> updateMerchant($merchantInfo);
    }
}